<template>
  <div>
    <el-table
      :data="bannerlist"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="title" label="轮播图标题"> </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <div>
            <img :src="$pre + scope.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.status == 1">启用</el-button>
            <el-button type="warning" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="success" @click="bianji(scope.row.id)">编辑</el-button>
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
import { mapActions, mapGetters } from "vuex";
import { bannerdelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../util/alert";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      reqbannerlist: "banner/reqchangelist",
    }),
    // 点击删除
    del(id) {
      bannerdelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          // 刷新数据
          this.reqbannerlist();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    // 点击编辑
    bianji(id){
      this.$emit('bianji',id)
    }
  },
  computed: {
    ...mapGetters({
      bannerlist: "banner/list",
    }),
  },
  mounted() {
    this.reqbannerlist();
  },
};
</script>

<style scoped>
img {
  width: 100px;
  height: 100px;
}
</style>